package com.wandian.texas;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

import com.wandian.texas.db.CommonDaoManager;
import com.wandian.texas.entity.ConfigEntity;
import com.wandian.texas.entity.ServerListEntity;
import com.wandian.util.HashMap;

/**
 * @author long
 * @Create 2012-10-12 下午1:51:09
 * @QQ 108232706
 * @version 1.0
 * @description GameData
 */
public final class GameData {
	public static String CONFIGPATH = "E:/work/gameserver/src/main/resources/config/config.properties";
	public static boolean checkLoginOnly;
	public static float StakeToMoney;
	// 全局，服务器配置文件信息
	public static ServerListEntity SERVER;
	// 多线程并发原子操作
	public static AtomicInteger ONLINECOUNT = new AtomicInteger();
	// sessionObject的5个状态
	public static final short WAITINGCHECKUSER = 0;
	public static final short WAITINGCHECKSUCC = 1;
	public static final short CHECKUSERSUCC = 2;
	public static final short READYGAME = 3;
	public static final short NOTRECEIVEDATA = 4;
	public static final short DISCONNECT = 5;

	// 所有玩家的命令列表，sessionobject,cmd,data。dispatcherThread
	public static final short INFREELIST = 0;// 命令，在空闲资源里
	public static final short INADDTOUSELIST = 1;// 命令， 加入使用资源
	public static final short RUNNINGCMD = 2;// 命令， 已分配thread执行状态
	public static final short COMPLETECMD = 3;// 命令， thread执行execute完成状态

	// 全局数据
	public static long MAINSTARTTIME = 0;
	public static long MAINSTOPTIME = 0;
	public static long STARTTIME = 0;
	public static long STOPTIME = 0;
	public static long SERVICESTARTTIME = 0;
	public static long SERVICESTOPTIME = 0;

	public static int ROOMSEAT = 9;
	public static float ROOMMINBLIND = 100;
	public static float ROOMMAXBLIND = 200;
	public static float ROOMMINTAKE = 1000;
	public static float ROOMMAXTAKE = 5000;
	// 中心服务器数据区
	public static long CENTERSTARTTIME = 0;
	public static long CENTERSTOPTIME = 0;
	public static final HashMap<String, ConfigEntity> CONFIGS = new HashMap<String, ConfigEntity>();
	/**
	 * 全局读取的配置信息
	 */
	public static float[] CornucopiaRates = new float[3];
	private static float OffSetCornucopia;
	/**
	 * 当前发给客户端基积宝
	 */
	private static float Cornucopia;
	/**
	 * 当前发给客户端基积宝在未来30秒的增长数，如24*30或0
	 */
	private static int addCornucopiaPer30s;
	public static float ToCornucopiaRate;
	private static final ReentrantLock CornucopiaLock = new ReentrantLock();

	/**
	 * 未能与中心服连接盈利累计至，等于NotSendMoney
	 */
	private static float SystemTotalWin;
	private static final ReentrantLock SystemTotalWinLock = new ReentrantLock();

	public static void InCreaceCornucopia(float _cornucopia) {
		CornucopiaLock.lock();
		try {
			setCornucopia(Cornucopia + _cornucopia);
		} finally {
			CornucopiaLock.unlock();
		}
	}

	public static float getCornucopia() {
		CornucopiaLock.lock();
		try {
			return Cornucopia;
		} finally {
			CornucopiaLock.unlock();
		}
	}

	public static void setCornucopia(float cornucopia) {
		CornucopiaLock.lock();
		try {
			Cornucopia = cornucopia;
		} finally {
			CornucopiaLock.unlock();
		}
	}

	public static void InCreaceOffSetCornucopia(float _offSetCornucopia) {
		CornucopiaLock.lock();
		try {
			OffSetCornucopia += _offSetCornucopia;
//			Log.info("当前积宝盈余:" + OffSetCornucopia);
		} finally {
			CornucopiaLock.unlock();
		}
	}

	public static float getOffSetCornucopia() {
		CornucopiaLock.lock();
		try {
			return OffSetCornucopia;
		} finally {
			CornucopiaLock.unlock();
		}
	}

	public static void setOffSetCornucopia(float _offSetCornucopia) {
		CornucopiaLock.lock();
		try {
			OffSetCornucopia = _offSetCornucopia;
		} finally {
			CornucopiaLock.unlock();
		}
	}

	public static float getSystemTotalWin() {
		SystemTotalWinLock.lock();
		try {
			return SystemTotalWin;
		} finally {
			SystemTotalWinLock.unlock();
		}
	}

	public static void setSystemTotalWin(float systemTotalWin) {
		SystemTotalWinLock.lock();
		try {
			SystemTotalWin = systemTotalWin;
		} finally {
			SystemTotalWinLock.unlock();
		}
	}

	public static void InCreaceSystemTotalWin(float _systemTotalWin) {
		CornucopiaLock.lock();
		try {
			SystemTotalWin += _systemTotalWin;
//			Log.info("当前系统总盈利:" + SystemTotalWin);
		} finally {
			CornucopiaLock.unlock();
		}
	}

	/**
	 * 初始化系统全局的配置,对应表t_config
	 */
	public static boolean initDbConfig() {
		return CommonDaoManager.GameRoomDao(0).initDbConfig();
	}

	/**
	 * 系统全局的配置的CValue
	 * 
	 * @param key
	 * @return
	 */
	public static String getString(String key) {
		return CONFIGS.get(key).CValue;
	}

	/**
	 * 系统全局的配置的FValue
	 * 
	 * @param key
	 * @return
	 */
	public static float getFloat(String key) {
		return CONFIGS.get(key).FValue;
	}

	/**
	 * 系统全局的配置的CValue的数字形式
	 * 
	 * @param key
	 * @return
	 */
	public static int getInt(String key) {
		return Integer.valueOf(getString(key));
	}

	/**
	 * 定时器操作，15秒自动放弃 type=100
	 */
	public static final int TIMERTOFOLD = 100;
	/**
	 * 101
	 */
	public static final int TIMERTOOPERATIONNEXT = 101;
	/**
	 * 102,形成边池
	 */
	public static final int SHOWBONUSPOOL = 102;
	/**
	 * 103显示底牌
	 */
	public static final int SHOWCARD = 103;
	/**
	 * 104
	 */
	public static final int CMD_POTS = 104;
	/**
	 * 105
	 */
	public static final int BROADCASTGAMEOVER = 105;
	/**
	 * 106
	 */
	public static final int STARTNEWGAME = 106;
	public static final int CMD_SNAPCARDS_FLOP = 107;
	public static final int CMD_SNAPCARDS_TURN = 108;
	public static final int CMD_SNAPCARDS_RIVER = 109;
	public static final int CMD_CORNUCOPIA = 200;
	/**
	 * 中心服断开连接，游戏端定时去重连
	 */
	public static final int CMD_RECONNECT = 201;
	
	public static final int  LOOK_ON=100;
	/**
	 * 等待下一场
	 * @default
	 */
	public static final int  WAIT_NEXT_GAME=101;
	/**
	 * 正在玩游戏
	 * @default
	 */
	public static final int  PLAYING_GAME=102;
	/**
	 * 玩的掉线
	 * @default
	 */
	public static final int  PLAYING_CLOSE_SOCKE=103;
	/**
	 * 没玩都掉线
	 * @default
	 */
	public static final int  NO_PLAYING_CLOSE_SOCKE=105;
	/**
	 * 等待买入
	 * @default
	 */
	public static final int  WAIT_BUY_IN=104;
}
